package org.hackystat.ui.telemetryviewer.gwt.client;

import java.util.Iterator;

import org.hackystat.ui.telemetryviewer.gwt.client.ChartWidget.ChartHandler;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.StackPanel;
import com.google.gwt.user.client.ui.TabPanel;

/**
 *
 * Mockup01 application main class it creates two panels that display charts.
 *
 * @author Pavel Senin.
 *
 */
public class Mockup01 implements EntryPoint {

  /* the list of charts that could be displayed */
  protected ChartListHolder list = new ChartListHolder();

  // /* the current chart handler */
  // private ChartHandler curInfo;
  //
  // /* the current chart itself */
  // private ChartWidget curChart;
  //
  // /* chart description */
  // private HTML description = new HTML();

  /* the tab-stuffed widgets container */
  private StackPanel mainPanel = new StackPanel();

  /* the tab-panel itself */
  private TabPanel tabs = new TabPanel();

  /**
   * Application entry point that setups all elements at the page.
   */
  public void onModuleLoad() {

    /* setting up the tabs container */
    mainPanel.setStyleName("telemetryViewer-container");

    /* load all the charts in the chart list holder */
    loadCharts();

    /* load all the charts in the tabs */
    Iterator itr = this.list.iterator();
    while (itr.hasNext()) {
      ChartHandler handler = (ChartHandler) itr.next();
      tabs.add(handler.getInstance(), handler.getName());
    }

    tabs.selectTab(0);

    tabs.setStyleName("telemetryViewer-TabPanel");
    tabs.getTabBar().setStyleName("telemetryViewer-TabBar");
    tabs.getDeckPanel().setStyleName("telemetryViewer-TabPanelBottom");

    // tabs.getDeckPanel().setStyleName("chart-TabPanelBottom");
    //
    // tabs.getTabBar().setStyleName("chart-TabPanel-TabBar");
    // tabs.addTabListener(tabListener)

    tabs.setWidth("100%");
    tabs.setHeight("100%");

    mainPanel.add(tabs);

    RootPanel.get().add(mainPanel);
  }

  /**
   * Adds all charts to the list. Note that this DOES create actual instances of all charts yet
   * (they are NOT created on-demand). This can make a significant difference in startup time.
   *
   */
  protected void loadCharts() {
    list.addChart(ChartInfo.init());
    list.addChart(ChartJUnit.init());
    list.addChart(ChartDependency.init());
    list.addChart(JFCSServiceStaticTst.init());
  }

}
